/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
import java.net.*;
import java.io.*;
import java.util.concurrent.atomic.AtomicInteger;


public class Client implements Runnable{
    private final int port;
    
    private final String address;
    
    private final static AtomicInteger all_clients = new AtomicInteger(0);
    
    private int cur_client = all_clients.getAndIncrement();
    
    public Client() {
        port = 6666;
        address = "127.0.0.1";
    }
    
    public static void main(String[] arg) {
        Client client = new Client();
        client.start();
    }
    
    public void run() {
        start();
    }
    
    public void start() {
        try {
            InetAddress ipAddress = InetAddress.getByName(address); 
            Socket socket = new Socket(ipAddress, port); 

            InputStream sin = socket.getInputStream();
            OutputStream sout = socket.getOutputStream();

            DataInputStream in = new DataInputStream(sin);
            DataOutputStream out = new DataOutputStream(sout);

            while(true) {
                long num = in.readLong();
                System.out.println("Client : " + cur_client + " recieved " + num);
                //Thread.sleep(100);
                out.writeBoolean(true);
            }
        } catch (Exception x) {
            x.printStackTrace();
        }
    }
}
